#include <fal.h>
#include <drv_flash.h>

static int init(void);
static int read(long offset, uint8_t *buf, size_t size);
static int write(long offset, const uint8_t *buf, size_t size);
static int erase(long offset, size_t size);

const struct fal_flash_dev stm32f4_onchip_flash = {"onchip_flash", 0x08000000, 512 * 1024, 128 * 1024, {init, read, write, erase}};

static int init(void)
{
    /* do nothing now */
    return RT_EOK;
}

static int read(long offset, uint8_t *buf, size_t size)
{
    return stm32_flash_read(stm32f4_onchip_flash.addr + offset, buf, size);
}

static int write(long offset, const uint8_t *buf, size_t size)
{
    return stm32_flash_write(stm32f4_onchip_flash.addr + offset, buf, size);
}

static int erase(long offset, size_t size)
{
    return stm32_flash_erase(stm32f4_onchip_flash.addr + offset, size);
}
